#include "Tree.h"

namespace clovis {

	namespace core {

        Tree::Tree(){
            root = NULL;
        }

	    Tree::Tree(ClovisVariable * value){
	        root = new Node(value);
	    }

        Tree::~Tree(){
            delete root;
        }

        Node * Tree::getRoot(){
            return root;
        }

        void Tree::print(){
            root->print();
        }

        void Tree::addTree( Tree * tree , NODE_ADD_METHOD method ){

            if (root->getValue()->getName() == tree->getRoot()->getValue()->getName() ){

                root->setValue(tree->getRoot()->getValue());

                Node * n;
                std::list<Node*> tmp = tree->getRoot()->getSons();

                for (std::list<Node*>::iterator iter = tmp.begin() ; iter != tmp.end() ; iter++){
                    n = *iter;
                    root->addTree(n,method);
                }
            }else{
                io::Log::logOn(io::WARNING,"Tree's root are not equal","error.log");
            }
        }

	};

};
